﻿using System;
using System.Web.Security;
using System.ServiceModel.Web;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace EnterpriseServices.Service
{
    #region UserInfo members
    /// <summary>
    /// 
    /// </summary>
    [DataContract]
    public class UserInfo
    {
        string _Name;
        string _Email;
        string _PasswordQuestion;
        bool _IsApproved;
        bool _IsLockedOut;

        /// <summary>
        /// Gets or sets the email address.
        /// </summary>
        /// <value>The email.</value>
        [DataMember]
        public string Email
        {
            get
            {
                return _Email;
            }
            set
            {
                _Email = value;
            }
        }
        /// <summary>
        /// Gets or sets the password question.
        /// </summary>
        /// <value>The password question.</value>
        [DataMember]
        public string PasswordQuestion
        {
            get
            {
                return _PasswordQuestion;
            }
            set
            {
                _PasswordQuestion = value;
            }
        }
        /// <summary>
        /// Gets or sets a value indicating whether this instance is approved.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is approved; otherwise, <c>false</c>.
        /// </value>
        [DataMember]
        public bool IsApproved
        {
            get
            {
                return _IsApproved;
            }
            set
            {
                _IsApproved = value;
            }
        }
        /// <summary>
        /// Gets or sets a value indicating whether this instance is locked out.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is locked out; otherwise, <c>false</c>.
        /// </value>
        [DataMember]
        public bool IsLockedOut
        {
            get
            {
                return _IsLockedOut;
            }
            set
            {
                _IsLockedOut = value;
            }
        }
        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        [DataMember]
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="UserInfo"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="email">The email.</param>
        /// <param name="passwordQuestion">The password question.</param>
        /// <param name="isApproved">if set to <c>true</c> [is approved].</param>
        /// <param name="isLockedOut">if set to <c>true</c> [is locked out].</param>
        public UserInfo(string name, string email, string passwordQuestion, bool isApproved, bool isLockedOut)
        {
            Name = name;
            Email = email;
            PasswordQuestion = passwordQuestion;
            IsApproved = isApproved;
            IsLockedOut = isLockedOut;
        }
        public UserInfo()
        { }
    }
    #endregion

    /// <summary>
    /// 
    /// </summary>
    [ServiceContract(Name="MembershipService")]
    public interface IMembershipManager
    {
        /// <summary>
        /// Creates a new user that is not an Active Directory user.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">The password.</param>
        /// <param name="email">The email.</param>
        /// <param name="passwordQuestion">The password question.</param>
        /// <param name="passwordAnswer">The password answer.</param>
        /// <param name="isApproved">if set to <c>true</c> [is approved].</param>
        /// <returns></returns>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]

			void CreateUser(string userName, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved);
				/// <summary>
				/// Creates a new user that is not an Active Directory user.
				/// </summary>
				/// <param name="application">The application.</param>
				/// <param name="userName">Name of the user.</param>
				/// <param name="password">The password.</param>
				/// <param name="email">The email.</param>
				/// <param name="passwordQuestion">The password question.</param>
				/// <param name="passwordAnswer">The password answer.</param>
				/// <param name="isApproved">if set to <c>true</c> [is approved].</param>
				/// <returns></returns>
				[OperationContract]
				[TransactionFlow(TransactionFlowOption.Allowed)]
				void CreateUser(string userName);

        /// <summary>
        /// Deletes the specified user.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="deleteAllRelatedData">if set to <c>true</c> [delete all related data].</param>
        /// <returns></returns>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]
        bool DeleteUser(string userName, bool deleteAllRelatedData);

        /// <summary>
        /// Deletes all users,and optionally removed all relevant data
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="deleteAllRelatedData">if set to <c>true</c> [delete all related data].</param>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]
        void DeleteAllUsers(bool deleteAllRelatedData);

        /// <summary>
        /// Returns the user matching the specified email.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="email">The email.</param>
        /// <returns></returns>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]
        string GetUserNameByEmail(string email);

        /// <summary>
        /// Gets the number of users currently accessing an application
        /// </summary>
        /// <param name="application">The application.</param>
        /// <returns></returns>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]
        int GetNumberOfUsersOnline();

        /// <summary>
        /// Updates the user record and status. May require a password answer. Updates only, if the user os not an Active Directory user.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="email">The email.</param>
        /// <param name="oldAnswer">The old answer.</param>
        /// <param name="newQuestion">The new question.</param>
        /// <param name="newAnswer">The new answer.</param>
        /// <param name="isApproved">if set to <c>true</c> [is approved].</param>
        /// <param name="isLockedOut">if set to <c>true</c> [is locked out].</param>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]
        void UpdateUser(string userName, string email, string oldAnswer, string newQuestion, string newAnswer, bool isApproved, bool isLockedOut);

        /// <summary>
        /// ]Specifies the number of minutes after the last activity date-time stamp for a user during which the user is considered on-line. Returns the number of minutes after the last activity date-time stamp for a user during which the user is considered on-line
        /// </summary>
        /// <param name="application">The application.</param>
        /// <returns></returns>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]
        int UserIsOnlineTimeWindow();

        /// <summary>
        /// Returns all of the users in the database.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <returns></returns>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]
        string[] GetAllUsers();

        /// <summary>
        /// Gets the information from the data source for the specified user.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="userName">Name of the user.</param>
        /// <returns></returns>
        [OperationContract]
        [TransactionFlow(TransactionFlowOption.Allowed)]
        UserInfo GetUserInfo(string userName);
    }
}